package com.mall.service.item;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.mall.client.item.TableNumService;
import com.mall.custom.dao.read.TableNumReadMapper;
import com.mall.custom.dao.write.TableNumWriteMapper;
import com.mall.pojo.TableNum;
import com.mall.pojo.TableNumExample;
import com.mall.pojo.TableNumExample.Criteria;



@Service
public class TableNumServiceImpl implements TableNumService {

	@Autowired
	private TableNumReadMapper tableNumReadMapper;
	@Autowired
	private TableNumWriteMapper tableNumWriteMapper;
	@Override
	public List<TableNum> getTableNumByExample(TableNumExample tableNumExample) {
		
		return this.tableNumReadMapper.selectByExample(tableNumExample);
	}
	@Override
	public void insertTableNum(TableNum tableNum) {
		this.tableNumWriteMapper.insert(tableNum);
		
	}
	@Override
	public TableNum getTableNumById(Long tableNumId) {
		
		return this.tableNumReadMapper.selectByPrimaryKey(tableNumId);
	}
	@Override
	public void modifyTableNum(TableNum tableNumModify) {
		this.tableNumWriteMapper.updateByPrimaryKey(tableNumModify);
	}
	@Override
	public TableNum getTableNumByMallIdAndTable(Long mallId, String tableNumStr,Integer onlyKey) {
		if(mallId == null || tableNumStr.equals(null)){
			return null;
		}
		TableNumExample example = new TableNumExample();
		Criteria criteria = example.createCriteria();
		criteria.andMallIdEqualTo(mallId);
		criteria.andNumEqualTo(tableNumStr);
		if(onlyKey != null){
			criteria.andCommOnlyKeyEqualTo(onlyKey);
		}
		criteria.andStautsEqualTo(0);
		List<TableNum> tableNumList = this.tableNumReadMapper.selectByExample(example);
		TableNum tableNum = null;
		if(tableNumList.size()>0){
			tableNum = tableNumList.get(0);
		}
		return tableNum;
	}

}
